Why would random assignment to mosquito netting help here?
Causes
You have a headache. Jennifer gives you what looks like a pill. An hour later your headache goes away. How do you reason about whether or not the “pill” causes your headache to go away?
Experiments
x: wealth, z : using paxlovid, y : covid severity
Experiments
Which of these paths are causal for our question? non-causal?
Experiments
Experiments
is this path the causal path we’re interested in?
Experiments
if we can get an unbiased causal estimate of y ~ z using either set, what’s an argument for adjusting for x?
Adjustment Set
❓ Are there any paths that connect podcast to exam? Look for forks, colliders, or chains.
my_first_dag <- ggdag::dagify( x ~ y, y ~ z + w)ggdag(my_first_dag) +theme_dag()
Creating Your First DAG
my_first_dag <- ggdag::dagify( x ~ y, y ~ z + w)coordinates(my_first_dag) <-list(x =c(x =0.5,y =0,z =-0.5,w =-0.5),y =c(x =0,y =0,z =-0.25,w =0.25))ggdag(my_first_dag) +theme_dag()
Creating Your First DAG
my_first_dag <- ggdag::dagify( x ~ y, y ~ z + w)# ggdag(my_first_dag, layout = "time_ordered") + ggdag(my_first_dag, layout ="sugiyama") +theme_dag()
Creating Your First DAG
my_first_dag <- ggdag::dagify( x ~ y, y ~ z + w,exposure ="x",outcome ="z")ggdag(my_first_dag, layout ="time_ordered") +theme_dag()
Creating Your First DAG
library(ggplot2)my_first_dag <- ggdag::dagify( x ~ y , y ~ z + w, q ~ z + x,exposure ="x",outcome ="z")ggdag(my_first_dag, layout ="time_ordered") +theme_dag() +theme(legend.position ="top")
gender <-dagify( occ ~ discrim + abil, income ~ discrim + abil + occ, discrim ~ gend,outcome ="discrim",exposure ="income")ggdag(gender, layout ="time_ordered",node_size =20) +theme_dag()
From: Causal Inference the Mixtape (Cunningham)
Gender Pay Gap
ggdag_paths(gender) +theme_dag()
Gender Pay Gap
# from: https://mixtape.scunning.com/03-directed_acyclical_graphslibrary(tidyverse)tb <-tibble(female =ifelse(runif(10000)>=0.5,1,0),ability =rnorm(10000),discrimination = female,occupation =1+2*ability +0*female -2*discrimination +rnorm(10000),wage =1-1*discrimination +1*occupation +2*ability +rnorm(10000) )# open path d -> o -> ilm_1 <-lm(wage ~ female, tb)# open path d -> o <- a -> ylm_2 <-lm(wage ~ female + occupation, tb)# woo!lm_3 <-lm(wage ~ female + occupation + ability, tb)
Gender Pay Gap
summary(lm_1)
Call:
lm(formula = wage ~ female, data = tb)
Residuals:
Min 1Q Median 3Q Max
-18.726 -2.859 -0.055 2.916 14.153
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.95419 0.05926 32.98 <2e-16 ***
female -3.02009 0.08459 -35.70 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.229 on 9998 degrees of freedom
Multiple R-squared: 0.1131, Adjusted R-squared: 0.113
F-statistic: 1275 on 1 and 9998 DF, p-value: < 2.2e-16
Gender Pay Gap
summary(lm_2)
Call:
lm(formula = wage ~ female + occupation, data = tb)
Residuals:
Min 1Q Median 3Q Max
-5.8292 -0.9117 -0.0010 0.9218 5.1408
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.196475 0.019963 9.842 <2e-16 ***
female 0.628497 0.029882 21.033 <2e-16 ***
occupation 1.813026 0.006156 294.535 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.359 on 9997 degrees of freedom
Multiple R-squared: 0.9084, Adjusted R-squared: 0.9083
F-statistic: 4.954e+04 on 2 and 9997 DF, p-value: < 2.2e-16
Gender Pay Gap
summary(lm_3)
Call:
lm(formula = wage ~ female + occupation + ability, data = tb)
Residuals:
Min 1Q Median 3Q Max
-4.5080 -0.6892 -0.0075 0.6808 3.8340
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.00354 0.01727 58.10 <2e-16 ***
female -1.00509 0.02856 -35.19 <2e-16 ***
occupation 1.00273 0.01004 99.84 <2e-16 ***
ability 2.01209 0.02222 90.57 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.008 on 9996 degrees of freedom
Multiple R-squared: 0.9497, Adjusted R-squared: 0.9496
F-statistic: 6.286e+04 on 3 and 9996 DF, p-value: < 2.2e-16
Parent’s + Children’s Grades
Draw a DAG that looks at the relationship between Parent’s grades in high school and their children’s grades in high school. Include as many factors as you can think of!
Build this DAG using ggdag or dagitty and look at the possible adjustment sets!